package com.tsd.jxc.buy.service.impl;

import com.tsd.core.utils.HlpUtils;
import com.tsd.core.vo.PageBean;
import com.tsd.jxc.buy.dao.JxcBuyOrderDetailSodMapper;
import com.tsd.jxc.buy.entity.JxcBuyOrderDetailSod;
import com.tsd.jxc.buy.entity.JxcBuyOrderDetailSodExt;
import com.tsd.jxc.buy.service.JxcBuyOrderDetailSodService;
import com.tsd.service.BaseServiceImpl;
import com.tsd.system.entity.SysUser;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 描述：JxcBuyOrderDetailSod 服务实现层
 *
 * @author Hillpool
 * @date 2022/12/12 11:23:08
 */
@Service
public class JxcBuyOrderDetailSodServiceImpl extends BaseServiceImpl implements JxcBuyOrderDetailSodService {

    @Resource
    private JxcBuyOrderDetailSodMapper jxcBuyOrderDetailSodMapper;

    @Override
    public JxcBuyOrderDetailSod getJxcBuyOrderDetailSodById(Long id) throws Exception {
        return jxcBuyOrderDetailSodMapper.selectByPrimaryKey(id);
    }

    @Override
    public JxcBuyOrderDetailSodExt queryBySid(String sid) throws Exception {
        return jxcBuyOrderDetailSodMapper.selectBySid(sid);
    }

    @Override
    public void deleteJxcBuyOrderDetailSods(List<String> list, SysUser opUser) throws Exception {
        for (String sid : list) {
            JxcBuyOrderDetailSod old = jxcBuyOrderDetailSodMapper.selectBySid(sid);
            super.checkEmpty(old, "该记录不存在");
            super.autoInjectBaseData(old, opUser, TYPE_DELETE);
            jxcBuyOrderDetailSodMapper.updateByPrimaryKeySelective(old);
        }
    }

    @Override
    public void saveJxcBuyOrderDetailSod(JxcBuyOrderDetailSod record, SysUser opUser) throws Exception {
        if (HlpUtils.isEmpty(record.getId())) {
            super.autoInjectBaseData(record, opUser, this.TYPE_CREATE);
            jxcBuyOrderDetailSodMapper.insertSelective(record);
        } else {
            super.autoInjectBaseData(record, opUser, this.TYPE_UPDATE);
            jxcBuyOrderDetailSodMapper.updateByPrimaryKeySelective(record);
        }
    }

    @Override
    public List<JxcBuyOrderDetailSodExt> findJxcBuyOrderDetailSods(Map<String, Object> params, PageBean page) throws Exception {
        return jxcBuyOrderDetailSodMapper.selectByPage(params, page);
    }

    @Override
    public List<JxcBuyOrderDetailSodExt> findJxcBuyOrderDetailSods(Map<String, Object> params) throws Exception {
        return jxcBuyOrderDetailSodMapper.selectByParams(params);
    }
}